package com.ruoyi.business.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.business.domain.Equipmentinfo;
import com.ruoyi.business.service.IEquipmentinfoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 主设备台账Controller
 *
 * @author DL
 * @date 2025-07-01
 */
@RestController
@RequestMapping("/equipmentinfo")
public class EquipmentinfoController extends BaseController
{
    @Autowired
    private IEquipmentinfoService equipmentinfoService;

    /**
     * 查询主设备台账列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Equipmentinfo equipmentinfo)
    {
        startPage();
        List<Equipmentinfo> list = equipmentinfoService.selectEquipmentinfoList(equipmentinfo);
        return getDataTable(list);
    }

    /**
     * 导出主设备台账列表
     */
    @Log(title = "主设备台账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Equipmentinfo equipmentinfo)
    {
        List<Equipmentinfo> list = equipmentinfoService.selectEquipmentinfoList(equipmentinfo);
        ExcelUtil<Equipmentinfo> util = new ExcelUtil<Equipmentinfo>(Equipmentinfo.class);
        util.exportExcel(response, list, "主设备台账数据");
    }

    /**
     * 获取主设备台账详细信息
     */
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") String ID)
    {
        return success(equipmentinfoService.selectEquipmentinfoByID(ID));
    }

    /**
     * 新增主设备台账
     */
    @Log(title = "主设备台账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Equipmentinfo equipmentinfo)
    {
        return toAjax(equipmentinfoService.insertEquipmentinfo(equipmentinfo));
    }

    /**
     * 修改主设备台账
     */
    @Log(title = "主设备台账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Equipmentinfo equipmentinfo)
    {
        return toAjax(equipmentinfoService.updateEquipmentinfo(equipmentinfo));
    }

    /**
     * 删除主设备台账
     */
    @Log(title = "主设备台账", businessType = BusinessType.DELETE)
	@DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable String[] IDs)
    {
        return toAjax(equipmentinfoService.deleteEquipmentinfoByIDs(IDs));
    }

    /**
     * 查询主设备台账的厂商列表
     */
    @GetMapping("/getMakerList")
    public AjaxResult getMakerList()
    {
        return success(equipmentinfoService.getMakerList());
    }

    /**
     * 根据厂商查询主设备台账详细信息
     */
    @GetMapping(value = "/dataCode/{code}")
    public AjaxResult getInfoByCode(@PathVariable("code") String code)
    {
        return success(equipmentinfoService.selectEquipmentinfoByMaker(code));
    }

    /**
     * @author: xienian
     * @description:查询所有设备信息
     * @param:
     * @return: com.ruoyi.common.core.web.domain.AjaxResult
     * @date: 2025/7/3 10:26
     */
    @GetMapping("/queryDeviceDataList")
    public AjaxResult queryDeviceDataList(){
        return success(equipmentinfoService.queryDeviceDataList());
    }
}
